// pages/mine/mine.js
// my/mine/mine.js
Page({

  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    isHide: true,
    username: {
      name: "",
      touxiang: ""
    }
  },
  setfun() {
    wx.navigateTo({
      url: './set/set',
    })
  },
  cityfun() {
    wx.navigateTo({
      url: './city/city',
    })
  },
  telfun() {
    wx.makePhoneCall({
      phoneNumber: '17634019286'
    })
  },
  tuifun() {
    wx.navigateTo({
      url: './tui/tui',
    })
  },
  dingfun() {
    wx.navigateTo({
      url: './ding/ding',
    })
  },
  moneyfun() {
    wx.navigateTo({
      url: './money/money',
    })
  },
  mendianfun() {
    wx.navigateTo({
      url: './shopmen/shopmen',
    })
  },
  qiandaofun() {
    wx.navigateTo({
      url: './qian/qian',
    })
  },
  onLoad: function () {
    var that = this;
    // 查看是否授权
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          wx.getUserInfo({
            success: function (res) {
              wx.login({
                success: res => {
                  // wx.request({

                  //     url: 'https://api.weixin.qq.com/sns/jscode2session?appid=自己的APPID&secret=自己的SECRET&js_code=' + res.code + '&grant_type=authorization_code',
                  //     success: res => {


                  //     }
                  // });
                }
              });
            }
          });
        } else {
          // 用户没有授权
          // 改变 isHide 的值，显示授权页面
          that.setData({
            isHide: true
          });
        }
      }
    });
  },

  bindGetUserInfo: function (e) {
    if (e.detail.userInfo) {
      var that = this;
      // console.log(e.detail.userInfo.avatarUrl);
      that.setData({
        isHide: false,
        username: {
          name: e.detail.userInfo.nickName,
          touxiang: e.detail.userInfo.avatarUrl
        }
      });
      wx.setStorage({
        key: "dxdusername",
        data: this.data.username
      })
    } else {
      wx.showModal({
        title: '警告',
        content: '您点击了拒绝授权，将无法进入小程序，请授权之后再进入!!!',
        showCancel: false,
        confirmText: '返回授权',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击了“返回授权”');
          }
        }
      });
    }
  },
  jumpfabufun() {
    wx.navigateTo({
      url: './fabu/fabu',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this
    // console.log(e.detail.userInfo);
    wx.getStorage({
      key: 'dxdusername',
      success(res) {
        that.setData({
          username: res.data
        });
        // console.log(res.data)
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})